const host = 'https://tkapp.tong-kuai.com/'
// const host = 'http://localhost/'
const imageurl = host + 'data/upload/'

const wxRequest = (params, url) => {
  wx.showToast({
    title: '加载中',
    icon: 'loading'
  })
  wx.request({
    url: url,
    method: params.method || 'GET',
    data: params.data || {},
    header: {
      'Content-Type': 'application/json'
    },
    success: (res) => {
      params.success && params.success(res)
      wx.hideToast()
    },
    fail: (res) => {
      params.fail && params.fail(res)
    },
    complete: (res) => {
      params.complete && params.complete(res)
    }
  })
}

// 传递用户信息
const wxLogin = (params) => wxRequest(params, host + 'index.php?g=Api&m=Oauth&a=wxLogin')
// 获取首页数据
const getIndexData = (params) => wxRequest(params, host + 'index.php?g=Api&m=Index&a=index')
// 获取首页最新数据
const getNewcookbooks = (params) => wxRequest(params, host + 'index.php?g=Api&m=Index&a=getNewcookbooks')
// 获取一级分类banner及二级分类列表
const getClassifyBanner = (params) => wxRequest(params, host + 'index.php?g=Api&m=Cookbook&a=getClassifyBanner')
// 获取一级分类菜谱列表
const getCookbookList = (params) => wxRequest(params, host + 'index.php?g=Api&m=Cookbook&a=getCookbookList')
// 获取二级分类菜谱列表
const getSonCookbookList = (params) => wxRequest(params, host + 'index.php?g=Api&m=Cookbook&a=getSonCookbookList')
// 获取所有烹饪方法
const getCooking = (params) => wxRequest(params, host + 'index.php?g=Api&m=Cookbook&a=getCooking')
// 根据id获取菜谱详情
const getCookbookDetail = (params) => wxRequest(params, host + 'index.php?g=Api&m=Cookbook&a=getCookbookDetail')
// 获取用户收藏的所有菜谱列表
const getCollectCookbookList = (params) => wxRequest(params, host + 'index.php?g=Api&m=Cookbook&a=getCollectCookbookList')
//用户点赞
const addPraise = (params) => wxRequest(params, host + 'index.php?g=Api&m=Cookbook&a=addPraise')
// 用户取消点赞
const canclePraise = (params) => wxRequest(params, host + 'index.php?g=Api&m=Cookbook&a=canclePraise')
// 用户收藏
const addCollect = (params) => wxRequest(params, host + 'index.php?g=Api&m=Cookbook&a=addCollect')
// 用户取消收藏
const cancleCollect = (params) => wxRequest(params, host + 'index.php?g=Api&m=Cookbook&a=cancleCollect')
// 添加反馈记录
const addFeedback = (params) => wxRequest(params, host + 'index.php?g=Api&m=Feedback&a=addFeedback')
// 添加菜谱评论
const getReviewList = (params) => wxRequest(params, host + 'index.php?g=Api&m=Review&a=getReviewList')
// 用户发起评论添加提交
const addReview = (params) => wxRequest(params, host + 'index.php?g=Api&m=Review&a=addReview')
// 添加菜谱评论
const addReply = (params) => wxRequest(params, host + 'index.php?g=Api&m=Review&a=addReply')
// 获取菜谱详情页评论
const getReview = (params) => wxRequest(params, host + 'index.php?g=Api&m=Cookbook&a=getReview')
// 获取信息
const getInfos = (params) => wxRequest(params, host + 'index.php?g=api&m=Info&a=getInfos')

module.exports = {
  host,
  imageurl,
  wxLogin,
  getIndexData,
  getNewcookbooks,
  getClassifyBanner,
  getCookbookList,
  getSonCookbookList,
  getCooking,
  getCookbookDetail,
  getCollectCookbookList,
  addPraise,
  canclePraise,
  addCollect,
  cancleCollect,
  addFeedback,
  getReviewList,
  addReview,
  addReply,
  getReview,
  getInfos
}